import 'package:flutter/material.dart';
import 'package:flutter_app/MainProvider.dart';
import 'package:provider/provider.dart';

class AnimatePositive extends StatefulWidget {
  AnimatePositive({Key key, @required this.size,this.myProvider});
  final double size;
  final MainProvider myProvider;
  @override
  _AnimatePositiveState createState() => _AnimatePositiveState();
}

Animation animation3;

class _AnimatePositiveState extends State<AnimatePositive>
    with TickerProviderStateMixin {
  AnimationController controller1;
  AnimationController controller2;
  AnimationController controller3;

  Animation animation1;
  Animation animation2;

  Animation curAnimation;

  Color color;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller1 =
        AnimationController(vsync: this, duration: Duration(milliseconds: 200));
    controller2 =
        AnimationController(vsync: this, duration: Duration(milliseconds: 200));
    // controller3=AnimationController(vsync: this,duration: Duration(milliseconds: 80));

    animation1 = Tween(begin: 1.0, end: 0).animate(controller1)
      ..addListener(() {
        setState(() {});
      })
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          controller2.forward(from: 0);
          curAnimation = controller2;
          color = Colors.red;
        }
      });
    animation2 = Tween(begin: 0.0, end: 1.2).animate(controller2)
      ..addListener(() {
        setState(() {});
      })
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          // controller3.forward(from: 0);
          // curAnimation=controller3;
        }
      });
    controller1.forward();
    curAnimation = animation1;
    color = Colors.grey[100];
  }

  @override
  Widget build(BuildContext context) {
    MainProvider mainProvider = Provider.of(context);
    double rpx = MediaQuery.of(context).size.width / 750;
    return Container(
        width: 100 * rpx,
        height: 100 * rpx,
        child: GestureDetector(
          child: Icon(
            Icons.favorite,
            size: widget.size * curAnimation.value,
            color: color,
          ),
          onTap: () {
            mainProvider.changeFav();
            widget.myProvider.changeFav();
          },
        ),
      );
  }
}

class AnimateNative extends StatefulWidget {
  AnimateNative(this.change);
  final change;
  @override
  _AnimateNativeState createState() => _AnimateNativeState();
}

class _AnimateNativeState extends State<AnimateNative> with TickerProviderStateMixin {
  Animation animation1;
  Animation animation2;

  AnimationController controller1;
  AnimationController controller2;

  Animation curAnimation;

  Color color;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    controller1=AnimationController(vsync: this,duration: Duration(milliseconds: 200));
    controller2=AnimationController(vsync: this,duration: Duration(milliseconds: 100));

    animation1=Tween(begin: 1.0,end: 0.0).animate(controller1)..addListener(() {
      setState(() {
        
      });
    })..addStatusListener((status) {
      if(status==AnimationStatus.completed){
        controller2.forward();
        color=Colors.grey[100];
        curAnimation=animation2;
      }
    });
    animation2=Tween(begin: 0.0,end: 1.0).animate(controller2)..addListener(() {
      setState(() {
        
      });
    });
    color=Colors.red;
    controller1.forward();
    curAnimation=animation1;
  }
  @override
  Widget build(BuildContext context) {
    MainProvider mainProvider = Provider.of(context);
    double rpx=MediaQuery.of(context).size.width/750;
    return MultiProvider(
      providers: [ChangeNotifierProvider(create: (context) => MainProvider())],
      child: Container(
        width: 100*rpx,
        height: 100*rpx,
        child: GestureDetector(
          child: Icon(
            Icons.favorite,
            color: color,
            size: 55*curAnimation.value,
          ),
          onTap: () {
            widget.change();
          },
        ),
      ),
    );
  }
}
